using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using nmspUSUARIO;
using System.Web.Hosting;
using System.IO;

public partial class loggedin_Contacto : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnEnviar_Click(object sender, EventArgs e)
    {

        try
        {

            SmtpClient mySmtpClient = new SmtpClient();
            mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;

            string emailPickupDirectory = HostingEnvironment.MapPath("~/Emails al admin");
            if (!Directory.Exists(emailPickupDirectory)) {
                Directory.CreateDirectory(emailPickupDirectory);
            }
            mySmtpClient.PickupDirectoryLocation = emailPickupDirectory;


            Usuario usr = new Usuario(User.Identity.Name);

            // add from,to mailaddresses
            MailAddress from = new MailAddress(usr.getEmail(), User.Identity.Name);
            MailAddress to = new MailAddress("admin@example.com", "Admin");
            MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

            // set subject and encoding
            myMail.Subject =  txtAsunto.Text;
            myMail.SubjectEncoding = System.Text.Encoding.UTF8;

            // set body-message and encoding
            myMail.Body =  txtMensaje.Text;
            myMail.BodyEncoding = System.Text.Encoding.UTF8;
            // text or html
            myMail.IsBodyHtml = false;

            mySmtpClient.Send(myMail);
        }

        catch (SmtpException ex)
        {
            throw new ApplicationException
              ("SmtpException has occured: " + ex.Message);
        }
        catch (Exception ex)
        {
            throw ex;
        }


        txtAsunto.Text = "";
        txtMensaje.Text = "";
        Response.Redirect("../Default.aspx");
    }
}
